home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 5 / Example 5.10 / Debug / Shaders / objects.vs < prev    next >
Encoding:
Text File  |  2006-03-10  |  933 b   |  41 lines

  1. uniform extern float4x4 matW;
  2. uniform extern float4x4 matVP;
  3. uniform extern float3 DirToSun;
  4. uniform extern float3 mapSize;
  5.  
  6. struct VS_INPUT1
  7. {
  8.    float4 position : POSITION0;
  9.    float3 normal : NORMAL0;
  10.    float2 uv : TEXCOORD0;
  11. };
  12.  
  13. struct VS_OUTPUT1
  14. {
  15.    float4 position : POSITION0;
  16.    float2 uv : TEXCOORD0;
  17.    float2 uv2 : TEXCOORD1;
  18.    float  shade : TEXCOORD2;
  19. };
  20.  
  21. VS_OUTPUT1 Main(VS_INPUT1 input)
  22. {
  23.    VS_OUTPUT1 output = (VS_OUTPUT1)0;
  24.  
  25.    //transform World, View and Projection
  26.    float4 temp = mul(input.position, matW);
  27.    output.position = mul(temp, matVP);
  28.    input.normal = mul(input.normal, matW);
  29.  
  30.    //Directional Lighting
  31.    output.shade = max(0.0f, dot(normalize(input.normal), DirToSun));
  32.    output.shade = 0.2f + output.shade * 0.8f;
  33.  
  34.    //Set UV coordinates
  35.    output.uv = input.uv;
  36.    output.uv2 = float2(temp.x / mapSize.x, -temp.z / mapSize.y);
  37.  
  38.    return output;
  39. }
  40.  
  41.